# -*- coding:utf-8 -*- 
import os
#from django.shortcuts import render_to_response
from google.appengine.ext.webapp import template
from model import *
import chardet
from google.appengine.api import memcache
import logging
def render(name, data):
    temp = os.path.join(os.path.dirname(__file__), 'template','jqueryauto', name)
    return template.render(temp, data)




def get_obj(key):
	logging.log(logging.INFO,"key=%s"%key)
	key=string.strip(key)
	#key_obj=db.Key(encoded=key) 
	obj=memcache.get(key)
	if obj is None:
	#obj=db.get(key_obj)
		obj=ablum.all().filter('name =', str(key)).get()
		if obj is None:
			obj=ablum.all().filter('name =', '88f5db500777fad5cc4770da32c0657f').get()
			memcache.set(key ,obj.blob)
			return obj.blob
		else:
			memcache.set(key ,obj.blob)
			return obj.blob
	else:
		return obj



def qdata(key,dbname):
    #qdb=exec(''.jion([dbname,'.all()'])
    pass

    
def code_data(tx):
        try:
            message_body=tx.encode('utf-8')
        except:
            nb_encode=chardet.detect(tx) 
            nb_code=nb_encode['encoding']
                #logging.info(nb_code)
            message_body=tx.decode(nb_code,'ignore').encode('utf-8')
        return unicode(message_body,'utf-8','ignore')
    